const hello = (name:string) => {
    console.log(`hello,${name}`)
}

hello('typescript')

const error: string = ''

const foo: object = function() {} // [] // {}

const arr: number[] = [1,2,3]
function sum (...args: number[]) {
    return args.reduce((prev, current) => prev + current, 0)
}

console.log(sum(...arr))

const nums = [110, 120, 119, 112]
const res = nums.find(i => i > 0) // ts推断res类型为number或者undefined
const num1 = res as number // 明确res是一个number类型

interface Post {
    title: string
    content: string
    subtitle?: string
    readonly summary: string
}
function printPost (post: Post) {
    console.log(post.title)
    console.log(post.content)
}
// 显示要求传入的post参数必须要有title，content
printPost({
    title: 'title',
    content: 'content',
    summary: ''
})
interface Cachee {
    [key: string]: string
}
const cache: Cachee = {}
cache['name'] = 'name'

class Person {
    public name: string = 'init name'
    private age: number // 私有属性，只能内部访问
    protected readonly gender: boolean

    constructor (name: string, age: number) {
        this.name = name
        this.age = age
        this.gender = true
    }
}

class Student extends Person {
    protected constructor (name: string, age: number) {
        super(name, age)
        console.log(this.gender)
    }
    static create (name: string, age: number) {
        return new Student(name, age)
    }
}

class HighSchoolStudent extends Student {
    constructor (name: string, age: number) {
        super(name, age)
        console.log(this.gender)
    }
}
const jack = Student.create('jack', 19)
const tom = new Person('tom', 19)


interface EatAndRun {
    eat (food: string): void
    run (distance: number): void
}

class Persona implements EatAndRun {
    eat (food: string): void {

    }
    run (distance: number): void {

    }
}

abstract class Animal {
    eat (food: string): void {
        console.log('吃' + food)
    }
    abstract run (distance: number): void
}

class Dog extends Animal {
    run(distance: number): void {
        console.log('run ' + distance)
    }
}
const d = new Dog()
d.eat('')
d.run(100)

function createArray<T> (length: number, value: T):T[] {
    const arr = Array<T>(length).fill(value)
    return arr
}

const arr1 = createArray<number>(3, 100)